package com.eastfair.projectcore.enumeration;

import com.eastfair.annotation.base.BaseEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 数据隔离表
 * </p>
 *
 * @author ligang
 * @date 2022-10-11
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "DataIsolationBusinDataScopeEnum", description = "该子系统调用业务服务的数据隔离级别#{PROJECT:项目级别;SUB_SYSTEM:系统级别;TEAM:团队级别(如公司级别)-枚举")
public enum DataIsolationBusinDataScopeEnum implements BaseEnum {

    /**
     * PROJECT="项目级别"
     */
    PROJECT("项目级别"),
    /**
     * SUB_SYSTEM="系统级别"
     */
    SUB_SYSTEM("系统级别"),
    /**
     * TEAM="团队级别(如公司级别)"
     */
    TEAM("团队级别(如公司级别)"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static DataIsolationBusinDataScopeEnum match(String val, DataIsolationBusinDataScopeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static DataIsolationBusinDataScopeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(DataIsolationBusinDataScopeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "PROJECT,SUB_SYSTEM,TEAM", example = "PROJECT")
    public String getCode() {
        return this.name();
    }

}
